package com.quanyan.place.mail;

import org.apache.log4j.Logger;

import java.sql.*;


public class ConnectionManager {
	 private static Logger logger = Logger.getLogger(ConnectionManager.class);

	  private static String DRIVERNAME = "com.mysql.jdbc.Driver";

	  private static String URL = "jdbc:mysql://rdsqi8tr186eo6841408.mysql.rds.aliyuncs.com:3306/quncaoapp?autoReconnect=true&autoReconnectForPools=true";
	  private static String USER = "quncao";
	  private static String PASSWORD = "quncao888";
	  
	  private static Connection getConnection(String url, String user, String password) {
	    try {
	      Class.forName(DRIVERNAME);
	      return DriverManager.getConnection(url, user, password);
	    }
	    catch (ClassNotFoundException e) {
	      e.printStackTrace();
	    } catch (SQLException e) {
	      e.printStackTrace();
	    }
	    return null;
	  }

	  public static Connection getConnection() {
	    return getConnection(URL, USER,PASSWORD);
	  }
	  
	  public static void closeConnection(Connection con, PreparedStatement ps, ResultSet rs) {
	      try {
			  if (null != rs)
	          	rs.close();
			  if (null != ps)
	          	ps.close();
			  if (null != con)
	          	con.close();
	     } catch (SQLException e) {
	      logger.error("连接关闭错误");
	      e.printStackTrace();
	    }
	}
}
